package com.biostime.springdraw.modules.sys.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.biostime.springdraw.common.persistence.Page;
import com.biostime.springdraw.common.persistence.TreeList;
import com.biostime.springdraw.common.service.TreeService;
import com.biostime.springdraw.modules.sys.dao.MenuDao;
import com.biostime.springdraw.modules.sys.entity.Menu;

/**
 * 菜单表Service
 * @author phil
 * @version 2015-11-06
 */
@Service
@Transactional
public class MenuService extends TreeService<MenuDao, Menu> {
	
	@Override
	public Page<Menu> findPage(Page<Menu> page, Menu entity) {
		page.setOrderBy("a.layer,a.sort");
		entity.setPage(page);
		
		TreeList<Menu> treeList = new TreeList<Menu>(dao.findList(entity),null);
		
		page.setList(treeList.toList());
		
		return page;
	}

	public List<Menu> getParentsTree() {
		List<Menu> parents = dao.findList(new Menu());
		TreeList<Menu> treeList = new TreeList<Menu>(parents,"├ ");
		
		return treeList.toList();
	}
	
	public List<Menu> getAllMenu(){
		List<Menu> parents = dao.findAllList(new Menu());
		TreeList<Menu> treeList = new TreeList<Menu>(parents,"");
		
		return treeList.toList();
	}
}
